package com.lq.ecoldchain.ui.forgetpwd

import android.arch.lifecycle.MutableLiveData
import com.lq.ecoldchain.base.viewmodel.BaseViewModel
import com.lq.ecoldchain.internet.BaseObserver
import com.lq.ecoldchain.util.MD5
import com.lq.ecoldchain.util.toast

/*
*2018/12/23 0023  17:43
*function by lq
*/
class PwdViewModel:BaseViewModel(){

    val phone by lazy { MutableLiveData<String>() }
    val code by lazy { MutableLiveData<String>() }
    val loginPassword by lazy { MutableLiveData<String>() }
    val confirmCode by lazy { MutableLiveData<String>() }
    val pwdCanSee by lazy { MutableLiveData<Boolean>() }
    val pwdAgainCanSee by lazy { MutableLiveData<Boolean>() }


    fun sendCode() {
        if (phone.value.isNullOrEmpty()) {
            toast { "请填写手机号码" }
        } else {
            BaseNetCore.ApiServiceImpl.sendResetPasswordCode(phone.value!!).compose(RxTransformer.switchSchedulers()).subscribe(object: BaseObserver<String>(){
                override fun onSuccess(t: String?) {}

                override fun onFail(code: String) {}
            })
        }
    }

    fun forget(){
        if(phone.value.isNullOrEmpty()|| loginPassword.value.isNullOrEmpty()||code.value.isNullOrEmpty()){
            toast { "请填写完整信息" }
        }else{
            BaseNetCore.ApiServiceImpl.resetPassword(phone.value!!,code.value!!,MD5.encode(loginPassword.value!!)).compose(RxTransformer.switchSchedulers()).subscribe(object:BaseObserver<String>(){
                override fun onSuccess(t: String?) {}

                override fun onFail(code: String) {}
            })
        }
    }
}